<?php

class ManageClicklinkAction extends LtAction
{
	public function __construct()
	{
		parent::__construct();
		$this->responseType = 'tpl';
		$this->layout = 'bylayout';
	}

	public function execute()
	{
		$this->template = "Manage-Error";

		$this->data['title'] = 'manage click link';

		$cid = $this->context->get('cid');
		$linkid = $this->context->get('linkid');
		if(empty($cid) || empty($linkid ))
		{
			$noticeStr = "cid or linkid miss";
		}
		else
		{
			$tmpcdao = new CustomerDao();
			$cqueryre = $tmpcdao->getByid($cid);
			if(empty($cqueryre))
			{	
				$noticeStr = "fail to find cid={$cid}";
			}
			else
			{
				$tmpldao = new HyperlinkDao();
				$lqueryre = $tmpldao->getByid($linkid);
				if(empty($lqueryre))
				{	
					$noticeStr = "fail to find linkid={$linkid}";
				}
				else
				{
					$tmpdao = new VisitlogDao();
					$addarr = array('cid'=>$cid, 'linkid'=>$linkid);
					$addre = $tmpdao->add($addarr);
					if($addre)
					{
						header('Location: '.$lqueryre['urlstr']);
					}
					$noticeStr = "fail to do add visitlog";
				}
			}
		}

		$this->data['noticestr'] = "<div class='warning'>{$noticeStr}</div>";
		
		$this->data['headnavbar']['visitlog'] = '';
		$this->data['headnavbar']['hyperlink'] = '';
		$this->data['headnavbar']['customer'] = '';
		$this->data['headnavbar']['index'] = '';
	}
}
